package org.net.cms.mapper;

import org.apache.ibatis.annotations.*;
import org.net.cms.controller.admin.student.vo.StudentReqVO;
import org.net.cms.dao.StudentDto;

import java.util.List;

@Mapper
public interface StudentMapper {

    @Insert("INSERT INTO student " +
            "(parent_card_id, parent_phone, student_card_id, name, sex, birthday, domicile) " +
            "VALUES " +
            "(#{parentCardId}, #{parentPhone}, #{studentCardId}, #{name}, #{sex}, #{birthday}, #{domicile})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addStudent(StudentDto studentDto);

    // 修改学生信息
    @Update("UPDATE student " +
            "SET parent_card_id = #{parentCardId}, " +
            "    parent_phone = #{parentPhone}, " +
            "    student_card_id = #{studentCardId}, " +
            "    name = #{name}, " +
            "    sex = #{sex}, " +
            "    birthday = #{birthday}, " +
            "    domicile = #{domicile} " +
            "WHERE id = #{id} AND deleted = 0")
    int updateStudent(StudentReqVO studentDto);

    //软删除学生
    @Update("update student set deleted = 1 where id = #{id}")
    int deleteStudent(int id);

    // 根据学生身份证号查询学生id
    @Select("select id from student where student_card_id = #{studentCardId} and deleted = 0")
    int getStudentId(String studentCardId);

    // 根据学生id查询学生信息
    @Select("select * from student where id = #{id} and deleted = 0")
    StudentDto getStudent(int id);

    @Select("select * from student where deleted = 0")
    List<StudentDto> findAll();
}
